home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-03 / s3bas11.zip / READMEM.BAS < prev    next >
BASIC Source File  |  1993-04-30  |  3KB  |  64 lines

  1. '*****************************************************
  2. ' This is an example of using PEEK to read the user
  3. ' specified contents of memory.  READMEM.BAS
  4. '
  5. ' By:  George Spafford  Copyright 1993
  6. '                       All Rights Reserved
  7. '
  8. ' No external libraries are required
  9. '
  10. ' v1.0  04/30/93
  11. '
  12. '*****************************************************
  13.  
  14. DEFINT A-Z
  15.  
  16. Title$ = "S3 Demo of Reading Memory v1.0         Copyright George Spafford 04/30/93"
  17. CLS
  18. PRINT Title$
  19. PRINT
  20. LOCATE 3, 40: PRINT "Specify a value preceded by &H if you"
  21. LOCATE 4, 40: PRINT "want to use hex numbers.  For example"
  22. LOCATE 5, 40: PRINT "&H400 is 400H or 1024 integer."
  23. LOCATE 3, 1
  24.  
  25. 'One neat ability of BASIC is its ability to have a hexadecimal value
  26. 'specified during input and convert it on the fly.  In this example, I
  27. 'am not performing any error trapping.  Usually, I input to a string,
  28. 'check and see if it is NULL and then exit the program.  It serves as
  29. 'a back door for users who want to exit the program.  Here, I am just
  30. 'inputting directly do an integer. If the user enters a hex value in the
  31. 'form of &Hnnnn, the program will use it.  However, if they get carried
  32. 'away, they can cause an overflow condition by exceding the bounds of
  33. 'an integer.
  34.  
  35. INPUT "Segment:  ", Segment
  36. INPUT "Offset :  ", Offset
  37. INPUT "Bytes  :  ", Length
  38.  
  39. PRINT : PRINT
  40.  
  41. DEF SEG = Segment                                   'set default segment to 0000
  42. FOR n = Offset TO (Offset + (Length - 1)) STEP 1    'start at offset and look at
  43.                                                     'at the bytes
  44.     T$ = HEX$(PEEK(n))                              'get the values at offset
  45.     IF LEN(T$) = 1 THEN T$ = "0" + T$               'HEX$ doesn't add "0" if
  46.                                                     'it is the first byte.
  47.     PRINT T$; " ";                                  'print it
  48.     CharLine = CharLine + 1                         'track hex codes one screen
  49.     IF CharLine = 8 AND Length <> 8 THEN            'if 8 codes and user wanted
  50.                                                     'more than eight, add hyphen
  51.        PRINT "- ";
  52.     END IF
  53.     IF CharLine = 16 THEN                           'if 16 codes on screen, then
  54.        PRINT                                        'do a line feed
  55.        CharLine = 0
  56.     END IF
  57. NEXT n                                      'do next n
  58. DEF SEG                                     'return to BASIC segment
  59.  
  60. PRINT
  61. END
  62.  
  63.  
  64.